package cn.imust.final_test;

import androidx.appcompat.app.AppCompatActivity;

import android.content.ContentResolver;
import android.database.CharArrayBuffer;
import android.database.ContentObserver;
import android.database.Cursor;
import android.database.DataSetObserver;
import android.database.sqlite.SQLiteCursorDriver;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteQuery;
import android.net.Uri;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import cn.imust.final_test.dao.DatabaseHelper;
import cn.imust.final_test.entity.Cdinfo;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ListView listView=(ListView) findViewById(R.id.listView);

        DatabaseHelper dao=new DatabaseHelper(MainActivity.this,"test_cdinfo",null,1);
        List<Cdinfo> datalist=dao.queryAll();
        ArrayList<HashMap<String,Object>> list=new ArrayList<HashMap<String,Object>>();
        for (Cdinfo cdinfo : datalist) {
            HashMap <String,Object> map=new HashMap <String,Object>();
            map.put("id", cdinfo.getId());
            map.put("type", cdinfo.getType());
            list.add(map);
        }
        SimpleAdapter adapter=new SimpleAdapter(MainActivity.this,
        list,R.layout.item, new String[]{"id","type"},
        new int[]{R.id.id,R.id.type});
        listView.setAdapter(adapter);
    }


}
